package com.lmiot.xyclick.Bean.SQL;

import android.content.Context;
import com.lmiot.xyclick.Bean.SQL.DaoMaster;
import com.lmiot.xyclick.Bean.SQL.SaveVoiceBeanDao;
import java.util.ArrayList;
import java.util.List;
import org.greenrobot.greendao.query.WhereCondition;

public class VoiceSqlUtil {
    private static final VoiceSqlUtil ourInstance = new VoiceSqlUtil();
    private SaveVoiceBeanDao mSaveVoiceBeanDao;

    public static VoiceSqlUtil getInstance() {
        return ourInstance;
    }

    private VoiceSqlUtil() {
    }

    public void initDbHelp(Context context) {
        this.mSaveVoiceBeanDao = new DaoMaster(new DaoMaster.DevOpenHelper(context, "recluse-db", null).getWritableDatabase()).newSession().getSaveVoiceBeanDao();
    }

    public void add(SaveVoiceBean saveVoiceBean) {
        this.mSaveVoiceBeanDao.insertOrReplace(saveVoiceBean);
    }

    public void addList(List<SaveVoiceBean> list) {
        this.mSaveVoiceBeanDao.insertOrReplaceInTx(list);
    }

    public void update(SaveVoiceBean saveVoiceBean) {
        this.mSaveVoiceBeanDao.update(saveVoiceBean);
    }

    public void del(String str) {
        ArrayList arrayList = (ArrayList) this.mSaveVoiceBeanDao.queryBuilder().where(SaveVoiceBeanDao.Properties.Voice_id.eq(str), new WhereCondition[0]).list();
        if (arrayList.size() > 0) {
            this.mSaveVoiceBeanDao.delete((SaveVoiceBean) arrayList.get(0));
        }
    }

    public void delAll() {
        this.mSaveVoiceBeanDao.deleteInTx(this.mSaveVoiceBeanDao.queryBuilder().build().list());
    }

    public List<SaveVoiceBean> searchAll() {
        List<SaveVoiceBean> list = this.mSaveVoiceBeanDao.queryBuilder().build().list();
        return list == null ? new ArrayList() : list;
    }
}
